//
//  MainFirst_ScrollView_WX.m
//  ZITHER
//
//  Created by weixin on 2019/3/15.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "MainFirst_ScrollView_WX.h"
#import "MainFirst_WX.h"
#define backHeight (Is_Iphone_X_Series ? kStatusBarHeight+10+20 : kStatusBarHeight+10+20+5)
#define bottomH (Is_Iphone_X_Series ? 80 : 45)

@implementation MainFirst_ScrollView_WX


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
        [self setUI];
        
    }
    return self;
}


-(void)defaultConfiguration{
    self.bounces = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.bounces = NO; // 默认为YES 取消设置NO
    // 当bounces属性为NO时，以下两个属性设置无效
    self.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
    self.alwaysBounceVertical = YES; // 垂直方向弹簧效果
    self.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
    self.backgroundColor = [UIColor whiteColor];
    self.pagingEnabled = YES;
    self.contentSize = CGSizeMake(kScreenW*2,0);
    self.delegate = self;
}

-(void)setUI{
    [self addSubview:self.TbvFirst];
    [self addSubview:self.TbvTwo];

}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (scrollView.contentOffset.x == 0) {
        [self changePage:0];
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH){
        [self changePage:1];
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH*2){
        [self changePage:2];
    }else{
        //        [self changePage:2];
    }
}



-(void)changePage:(int)index{
    MainFirst_WX *vc  = (MainFirst_WX*)[self getViewController:[MainFirst_WX class]];
    [vc.TitleV changeBtn:index];
}



- (MainFirst_Tbv_WX *)TbvFirst{
    if (!_TbvFirst) {
        _TbvFirst = [[MainFirst_Tbv_WX alloc]initializeFrame:CGRectMake(0, 0, kScreenW,kScreenH-bottomH-TabbarHeight) isMj:1 isEstimatedRowHeight:YES addRegisterNib:@[@"MainFirst_MagazineList_PGCCell_WX",@"MainFirst_MagazineListToeknWX_PGCCell_WX"]];
        _TbvFirst.Style = MainFirst_Tbv_WXStyleRecommend;
//        _tbv1.indexType = @"0";
    }
    return _TbvFirst;
}

- (MainFirst_Tbv_WX *)TbvTwo{
    if (!_TbvTwo) {
        _TbvTwo = [[MainFirst_Tbv_WX alloc]initializeFrame:CGRectMake(kScreenW, 0, kScreenW, kScreenH-bottomH-TabbarHeight) isMj:1 isEstimatedRowHeight:YES addRegisterNib:@[@"MainFirst_Magazine_Cell_WX",@"MainFirst_MagazineListToeknWX_PGCCell_WX"]];
//        _TbvTwo.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 20)];
//        _tbv2.indexType = @"1";
        _TbvTwo.Style = MainFirst_Tbv_WXStyleNewest;

    }
    return _TbvTwo;
}


@end
